package ClassicalCryptography;

import java.util.Map;

public class MonoSubCipher {

    public String encrypt(String plaintext, Map<Character, Character> keyBox) {
        StringBuilder res = new StringBuilder(plaintext.length());
        for (int i = 0; i < plaintext.length(); i++) {
            res.append(keyBox.get(plaintext.charAt(i)));
        }
        return res.substring(0);
    }

    public String decrypt(String ciphertext, Map<Character, Character> invKeyBox) {
        StringBuilder res = new StringBuilder(ciphertext.length());
        for (int i = 0; i < ciphertext.length(); i++) {
            res.append(invKeyBox.get(ciphertext.charAt(i)));
        }
        return res.substring(0);
    }


}
